<?php

namespace TuxCocktail\TuxDb\Mysql\Cocktail;

use TuxCocktail\TuxDb\Mysql\Cocktail\Model\PouringTechinqueTypeTable;

use TuxCocktail\TuxDb\Mysql\Cocktail\Model\PouringSpeedTypeTable;

use TuxCocktail\TuxDb\Mysql\Cocktail\Model\PouringLocationTypeTable;

use TuxCocktail\TuxDb\TuxPouringTechniqueInterface;
use TuxCocktail\TuxDb\Mysql\TuxDbMysqlAbstract;

class TuxDbMysqlPouringTechnique extends TuxDbMysqlAbstract implements TuxPouringTechniqueInterface {
	
	/**
	 * 
	 * @var PouringLocationTypeTable
	 */
	private $pouringLocationTypeTable;
	
	/**
	 * 
	 * @var PouringSpeedTypeTable
	 */
	private $pouringSpeedTypeTable;
	
	/**
	 * 
	 * @var PouringTechinqueTypeTable
	 */
	private $pouringTechniqueTypeTable;

	/**
	 * 
	 * @return \TuxCocktail\TuxDb\Mysql\Cocktail\Model\PouringLocationTypeTable
	 */
	private function getPouringLocationTypeTable() {
		if (!$this->pouringLocationTypeTable) {
			$this->pouringLocationTypeTable = new PouringLocationTypeTable($this->tuxDb->getInstance());
		}
		return $this->pouringLocationTypeTable;
	}
	
	/**
	 * 
	 * @return \TuxCocktail\TuxDb\Mysql\Cocktail\Model\PouringSpeedTypeTable
	 */
	private function getPouringSpeedTypeTable() {
		if (!$this->pouringSpeedTypeTable) {
			$this->pouringSpeedTypeTable = new PouringSpeedTypeTable($this->tuxDb->getInstance());
		}
		return $this->pouringSpeedTypeTable;
	}
	
	/**
	 * 
	 * @return \TuxCocktail\TuxDb\Mysql\Cocktail\Model\PouringTechniqueTypeTable
	 */
	private function getPouringTechniqueTypeTable() {
		if (!$this->pouringTechniqueTypeTable) {
			$this->pouringTechniqueTypeTable = new PouringTechinqueTypeTable($this->tuxDb->getInstance());
		}
		return $this->pouringTechniqueTypeTable;
	}
	
	
	
	public function addPouringLocation($pouringLocation) {
		$table = $this->getPouringLocationTypeTable();
		$table->addPouringLocationType($pouringLocation);
	}
	
	public function addPouringSpeed($pouringSpeed) {
		$table=$this->getPouringSpeedTypeTable();
		$table->addPouringSpeedType($pouringSpeed);
	}
	
	public function addPouringTechnique($pouringTechniqueName,$pouringLocation,$pouringSpeed) {
		
		$pouringLocationTypetable = $this->getPouringLocationTypeTable();
		$pouringLocationTypeId = $pouringLocationTypetable->createIfNotExist(array('pouring_location_type_name'=>$pouringLocation));
		
		$pouringSpeedTypeTable = $this->getPouringSpeedTypeTable();
		$pouringSpeedTypeId = $pouringSpeedTypeTable->createIfNotExist(array('pouring_speed_type_name'=>$pouringSpeed));
		
		$pouringTechniqueTypeTable=$this->getPouringTechniqueTypeTable();
		$pouringTechniqueTypeTable->addPouringTechinqueType($pouringTechniqueName, $pouringSpeedTypeId, $pouringLocationTypeId);
		
	}
	
	public function getAllPouringLocations() {
			$pouringLocationTable = $this->getPouringLocationTypeTable();
			$select = $this->pouringLocationTypeTable->newSelect();
			$pouringLocationTable->getSelect($select, array('pouring_location_type_name'));
			$resultSet = $pouringLocationTable->selectWith($select);
			if ($resultSet->count() >0) {
				$arr = array();
				foreach ($resultSet as $row) {
					array_push($arr,$row->pouring_location_type_name);
				}
				return $arr;
			}
			return null;
	}
	
	public function getAllPouringSpeeds() {
		$pouringSpeedTable = $this->getPouringSpeedTypeTable();
		$select = $this->pouringSpeedTypeTable->newSelect();
		$pouringSpeedTable->getSelect($select, array('pouring_speed_type_name'));
		$resultSet = $pouringSpeedTable->selectWith($select);
		if ($resultSet->count() > 0) {
			$arr =array();
			foreach ($resultSet as $row) {
				array_push($arr,$row->pouring_speed_type_name);
			}
			return $arr;
		}
		return null;
		}
	
	
	
}
